
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Will
 */
public final class tablaUsuario extends javax.swing.JFrame {
Funciones f=new Funciones();
DefaultTableModel dt=new DefaultTableModel();
Connection conn;
ResultSet rs;
Statement stmt;
char pass[]=new char[10];
char pass2[]=new char[10];
int contClic=0;//Controla los textfield de los telefonos extra
int cambioTF=1; //Controla la busqueda del tfBuscar para clientes activos y desactivados
int AoM=0;  //AoM=Agregar o Modificar: variable que controla si se agrega o modifica en el jDialog Agregar=0,Modificar=1
   /**
     * Creates new form tablaCliente
     */
    public tablaUsuario() {
        initComponents();
        //lblTitulo.setText("Usuarios Activos del sistema");
        dt.addColumn("Código");
        dt.addColumn("Nombre");
        dt.addColumn("Primer Apellido");
        dt.addColumn("Dirección");
        dt.addColumn("Puesto");
        dt.addColumn("Usuario");
        tablaClientes.setModel(dt);
        tablaClientes.removeColumn(tablaClientes.getColumn(0));
        btnDarAlta.setVisible(false);
        btnAtras.setVisible(false);
        String sql="SELECT * FROM usuarios WHERE activo=1"; 
        mostrarTabla(sql);
        estadoTelefono();
        tfPass1.setEchoChar('ʘ');
        tfPass2.setEchoChar('ʘ');
        
    }
    public void estadoTelefono(){
        l1.setVisible(false);
        l2.setVisible(false);
        l3.setVisible(false);
        l4.setVisible(false);
        l5.setVisible(false);
        tfTel1.setVisible(false);
        tfTel2.setVisible(false);
        tfTel3.setVisible(false);
        tfTel4.setVisible(false);
        tfTel5.setVisible(false);
    }
    
    
    public void mostrarTabla(String sql){
        conn=Conexion.obtenerConexion();
        dt.setRowCount(0);
        try {
            stmt=conn.createStatement();
            rs=stmt.executeQuery(sql);
            while(rs.next()){
                dt.addRow(new Object[]{rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(5),rs.getString(6),rs.getString(8)});
            }
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(tablaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdAccion = new javax.swing.JDialog();
        panelRect4 = new org.edisoncor.gui.panel.PanelRect();
        lblTitulo2 = new org.edisoncor.gui.label.LabelMetric();
        panelRect5 = new org.edisoncor.gui.panel.PanelRect();
        panelCurves2 = new org.edisoncor.gui.panel.PanelCurves();
        btnGuardar = new org.edisoncor.gui.button.ButtonIpod();
        btnLimpiar = new org.edisoncor.gui.button.ButtonIpod();
        btnCancelar = new org.edisoncor.gui.button.ButtonIpod();
        panelRound1 = new org.edisoncor.gui.panel.PanelRound();
        panelImage2 = new org.edisoncor.gui.panel.PanelImage();
        labelMetric4 = new org.edisoncor.gui.label.LabelMetric();
        tfNom = new org.edisoncor.gui.textField.TextFieldRectBackground();
        labelMetric5 = new org.edisoncor.gui.label.LabelMetric();
        tfApe1 = new org.edisoncor.gui.textField.TextFieldRectBackground();
        labelMetric6 = new org.edisoncor.gui.label.LabelMetric();
        tfApe2 = new org.edisoncor.gui.textField.TextFieldRectBackground();
        tfDir = new org.edisoncor.gui.textField.TextFieldRectBackground();
        labelMetric7 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric8 = new org.edisoncor.gui.label.LabelMetric();
        tfTel = new javax.swing.JFormattedTextField();
        l2 = new org.edisoncor.gui.label.LabelMetric();
        l3 = new org.edisoncor.gui.label.LabelMetric();
        l4 = new org.edisoncor.gui.label.LabelMetric();
        tfTel3 = new javax.swing.JFormattedTextField();
        tfTel4 = new javax.swing.JFormattedTextField();
        tfTel2 = new javax.swing.JFormattedTextField();
        btnAdd = new org.edisoncor.gui.button.ButtonIcon();
        btnElim = new org.edisoncor.gui.button.ButtonIcon();
        l5 = new org.edisoncor.gui.label.LabelMetric();
        tfTel5 = new javax.swing.JFormattedTextField();
        l1 = new org.edisoncor.gui.label.LabelMetric();
        tfTel1 = new javax.swing.JFormattedTextField();
        panelImage3 = new org.edisoncor.gui.panel.PanelImage();
        labelMetric9 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric10 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric11 = new org.edisoncor.gui.label.LabelMetric();
        labelMetric12 = new org.edisoncor.gui.label.LabelMetric();
        tfPass1 = new org.edisoncor.gui.passwordField.PasswordFieldRectIcon();
        tfPass2 = new org.edisoncor.gui.passwordField.PasswordFieldRectIcon();
        tfUsu = new org.edisoncor.gui.textField.TextFieldRectIcon();
        cbPuesto = new javax.swing.JComboBox();
        panelRect1 = new org.edisoncor.gui.panel.PanelRect();
        labelMetric1 = new org.edisoncor.gui.label.LabelMetric();
        panelRect2 = new org.edisoncor.gui.panel.PanelRect();
        panelCurves1 = new org.edisoncor.gui.panel.PanelCurves();
        btnNuevo = new org.edisoncor.gui.button.ButtonIpod();
        btnModificar = new org.edisoncor.gui.button.ButtonIpod();
        btnVerBajas = new org.edisoncor.gui.button.ButtonIpod();
        btnDarBaja = new org.edisoncor.gui.button.ButtonIpod();
        panelRect3 = new org.edisoncor.gui.panel.PanelRect();
        tfBuscar = new java.awt.TextField();
        labelMetric3 = new org.edisoncor.gui.label.LabelMetric();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        tablaClientes = new org.jdesktop.swingx.JXTable();
        btnDarAlta = new org.edisoncor.gui.button.ButtonIpod();
        btnAtras = new org.edisoncor.gui.button.ButtonIpod();

        jdAccion.setModal(true);

        lblTitulo2.setText("q=)+B");
        lblTitulo2.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        panelRect4.add(lblTitulo2);

        jdAccion.getContentPane().add(panelRect4, java.awt.BorderLayout.PAGE_START);

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/guardar.png"))); // NOI18N
        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelCurves2Layout = new javax.swing.GroupLayout(panelCurves2);
        panelCurves2.setLayout(panelCurves2Layout);
        panelCurves2Layout.setHorizontalGroup(
            panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCurves2Layout.createSequentialGroup()
                .addGap(189, 189, 189)
                .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelCurves2Layout.setVerticalGroup(
            panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelCurves2Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(panelCurves2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        panelImage2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos personales", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N

        labelMetric4.setText("Nombre(s):");

        labelMetric5.setText("Primer Apellido:");

        labelMetric6.setText("Segundo Apellido:");

        labelMetric7.setText("Dirección:");

        labelMetric8.setText("Teléfono:");

        try {
            tfTel.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfTel.setText("-");

        l2.setText("Teléfono:");

        l3.setText("Teléfono:");

        l4.setText("Teléfono:");

        try {
            tfTel3.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfTel3.setText("-");

        try {
            tfTel4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfTel4.setText("-");

        try {
            tfTel2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfTel2.setText("-");

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/add.png"))); // NOI18N
        btnAdd.setText("buttonIcon1");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnElim.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancel.png"))); // NOI18N
        btnElim.setText("buttonIcon1");
        btnElim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnElimActionPerformed(evt);
            }
        });

        l5.setText("Teléfono:");

        try {
            tfTel5.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfTel5.setText("-");

        l1.setText("Teléfono:");

        try {
            tfTel1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        tfTel1.setText("-");

        javax.swing.GroupLayout panelImage2Layout = new javax.swing.GroupLayout(panelImage2);
        panelImage2.setLayout(panelImage2Layout);
        panelImage2Layout.setHorizontalGroup(
            panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImage2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImage2Layout.createSequentialGroup()
                        .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelMetric6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMetric8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfDir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(panelImage2Layout.createSequentialGroup()
                                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tfNom, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfApe1, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfApe2, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(panelImage2Layout.createSequentialGroup()
                                        .addComponent(tfTel, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnElim, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(0, 187, Short.MAX_VALUE))))
                    .addGroup(panelImage2Layout.createSequentialGroup()
                        .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(panelImage2Layout.createSequentialGroup()
                                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(80, 80, 80)
                                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(tfTel4, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfTel3, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(panelImage2Layout.createSequentialGroup()
                                .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(tfTel5, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(panelImage2Layout.createSequentialGroup()
                                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(l2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(l1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(80, 80, 80)
                                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tfTel1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfTel2, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelImage2Layout.setVerticalGroup(
            panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImage2Layout.createSequentialGroup()
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfApe1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfApe2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tfDir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelMetric8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tfTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE)
                        .addComponent(btnElim, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addGap(8, 8, 8)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(panelImage2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(l5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        panelImage3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos de Usuario", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(255, 255, 255))); // NOI18N

        labelMetric9.setText("Usuario:");

        labelMetric10.setText("Contraseña:");

        labelMetric11.setText("Verifique\nContraseña"); // NOI18N

        labelMetric12.setText("Puesto:");

        tfPass2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tfPass2FocusLost(evt);
            }
        });

        cbPuesto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione...", "Vendedor", "Bodeguero", "Administrador" }));

        javax.swing.GroupLayout panelImage3Layout = new javax.swing.GroupLayout(panelImage3);
        panelImage3.setLayout(panelImage3Layout);
        panelImage3Layout.setHorizontalGroup(
            panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImage3Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelMetric9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric11, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(tfPass2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(tfPass1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(cbPuesto, 0, 123, Short.MAX_VALUE))
                    .addComponent(tfUsu, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        panelImage3Layout.setVerticalGroup(
            panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelImage3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfUsu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMetric10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPass1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelImage3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelImage3Layout.createSequentialGroup()
                        .addComponent(labelMetric11, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelMetric12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelImage3Layout.createSequentialGroup()
                        .addComponent(tfPass2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbPuesto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelRound1Layout = new javax.swing.GroupLayout(panelRound1);
        panelRound1.setLayout(panelRound1Layout);
        panelRound1Layout.setHorizontalGroup(
            panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRound1Layout.createSequentialGroup()
                .addGroup(panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(panelImage2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRound1Layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(panelImage3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        panelRound1Layout.setVerticalGroup(
            panelRound1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRound1Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(panelImage2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelImage3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelRect5Layout = new javax.swing.GroupLayout(panelRect5);
        panelRect5.setLayout(panelRect5Layout);
        panelRect5Layout.setHorizontalGroup(
            panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect5Layout.createSequentialGroup()
                .addGroup(panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelRect5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelCurves2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panelRect5Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(panelRound1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 28, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelRect5Layout.setVerticalGroup(
            panelRect5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRect5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelRound1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelCurves2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jdAccion.getContentPane().add(panelRect5, java.awt.BorderLayout.CENTER);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panelRect1.setColorPrimario(new java.awt.Color(0, 204, 204));

        labelMetric1.setText("USUARIOS");
        labelMetric1.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        panelRect1.add(labelMetric1);

        getContentPane().add(panelRect1, java.awt.BorderLayout.PAGE_START);

        panelRect2.setColorPrimario(new java.awt.Color(0, 102, 204));
        panelRect2.setColorSecundario(new java.awt.Color(0, 204, 204));

        panelCurves1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/add.png"))); // NOI18N
        btnNuevo.setText("Nuevo");
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
        panelCurves1.add(btnNuevo, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 0, 60, 60));

        btnModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/preferences-composer.png"))); // NOI18N
        btnModificar.setText("Modificar");
        btnModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarActionPerformed(evt);
            }
        });
        panelCurves1.add(btnModificar, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 0, 70, 60));

        btnVerBajas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/ver.png"))); // NOI18N
        btnVerBajas.setText("Ver Bajas");
        btnVerBajas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerBajasActionPerformed(evt);
            }
        });
        panelCurves1.add(btnVerBajas, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, -10, 70, 70));

        btnDarBaja.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/bajas.png"))); // NOI18N
        btnDarBaja.setText("Dar Baja");
        btnDarBaja.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDarBajaActionPerformed(evt);
            }
        });
        panelCurves1.add(btnDarBaja, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, -10, 70, 70));

        panelRect3.setColorPrimario(new java.awt.Color(0, 51, 204));
        panelRect3.setColorSecundario(new java.awt.Color(0, 153, 153));

        tfBuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfBuscarKeyReleased(evt);
            }
        });

        labelMetric3.setText("Buscar");

        tablaClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tablaClientes);

        btnDarAlta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/altas.png"))); // NOI18N
        btnDarAlta.setText("Dar Alta");
        btnDarAlta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDarAltaActionPerformed(evt);
            }
        });

        btnAtras.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/cancelar.png"))); // NOI18N
        btnAtras.setText("Atrás");
        btnAtras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtrasActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelRect3Layout = new javax.swing.GroupLayout(panelRect3);
        panelRect3.setLayout(panelRect3Layout);
        panelRect3Layout.setHorizontalGroup(
            panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect3Layout.createSequentialGroup()
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(panelRect3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnAtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDarAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(124, 124, 124)
                            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 428, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(205, 205, 205)
                            .addComponent(labelMetric3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(26, 26, 26)
                            .addComponent(tfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(panelRect3Layout.createSequentialGroup()
                            .addGap(25, 25, 25)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        panelRect3Layout.setVerticalGroup(
            panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect3Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelMetric3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelRect3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnDarAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAtras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout panelRect2Layout = new javax.swing.GroupLayout(panelRect2);
        panelRect2.setLayout(panelRect2Layout);
        panelRect2Layout.setHorizontalGroup(
            panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelRect2Layout.createSequentialGroup()
                .addGroup(panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelCurves1, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE)
                    .addGroup(panelRect2Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(panelRect3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panelRect2Layout.setVerticalGroup(
            panelRect2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelRect2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(panelRect3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelCurves1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getContentPane().add(panelRect2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnDarBajaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDarBajaActionPerformed
        // TODO add your handling code here:
        darBaja();
        
    }//GEN-LAST:event_btnDarBajaActionPerformed

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
        // TODO add your handling code here:
        AoM=0;
        contClic=0;
        lblTitulo2.setText("Agregar Usuario");
        tfApe1.setText("");
        tfApe2.setText("");
        tfDir.setText("");
        tfNom.setText("");
        tfPass1.setText("");
        tfPass2.setText("");
        tfTel.setText("");
        
        tfTel1.setText("");
        l1.setVisible(false);
        tfTel1.setVisible(false);
        tfTel2.setText("");
        l2.setVisible(false);
        tfTel2.setVisible(false);
        tfTel3.setText("");
        l3.setVisible(false);
        tfTel3.setVisible(false);
        tfTel4.setText("");
        l4.setVisible(false);
        tfTel4.setVisible(false);
        tfTel5.setText("");
        l5.setVisible(false);
        tfTel5.setVisible(false);
        tfUsu.setText("");
       jdAccion.pack();   
       jdAccion.setLocationRelativeTo(null);
       jdAccion.setVisible(true);
       
       
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnVerBajasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerBajasActionPerformed
        // TODO add your handling code here:
        cambioTF=0;
        //lblTitulo.setText("Usuarios Inactivos del sistema");
        
       
        btnDarAlta.setVisible(true);
        btnAtras.setVisible(true);
        String sql="SELECT * FROM usuarios WHERE activo=0";
        mostrarTabla(sql);
        btnModificar.setEnabled(false);
        btnDarBaja.setEnabled(false);
        btnNuevo.setEnabled(false);
    }//GEN-LAST:event_btnVerBajasActionPerformed

    private void btnDarAltaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDarAltaActionPerformed
        // TODO add your handling code here:
       darAlta();
    }//GEN-LAST:event_btnDarAltaActionPerformed

    private void btnAtrasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtrasActionPerformed
        // TODO add your handling code here:
         cambioTF=1;
      // lblTitulo.setText("Usuarios Activos del sistema");
        String sql="SELECT * FROM usuarios WHERE activo=1"; 
        mostrarTabla(sql);
        btnDarAlta.setVisible(false);
        btnAtras.setVisible(false);
        btnModificar.setEnabled(true);
        btnDarBaja.setEnabled(true);
        btnNuevo.setEnabled(true);
    }//GEN-LAST:event_btnAtrasActionPerformed

    private void tfBuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfBuscarKeyReleased
        // TODO add your handling code here:
        String nombre=tfBuscar.getText();
        String sql;
        if(cambioTF==1){
            sql="SELECT * FROM usuarios where (nombre like '%"+nombre+"%' or primerApellido like '%"+nombre+"%' or segundoApellido like '%"+nombre+"%') && activo=1";
        }else{
            sql="SELECT * FROM usuarios where (nombre like '%"+nombre+"%' or primerApellido like '%"+nombre+"%' or segundoApellido like '%"+nombre+"%') && activo=0";
        }
        
        mostrarTabla(sql);
    }//GEN-LAST:event_tfBuscarKeyReleased

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        // TODO add your handling code here:
        contClic++;
       
        if (contClic == 1) {
            l1.setVisible(true);
            tfTel1.setVisible(true);
        }
        if (contClic == 2) {
            l2.setVisible(true);
            tfTel2.setVisible(true);
        }
        if (contClic == 3) {
            l3.setVisible(true);
            tfTel3.setVisible(true);
        }
        if (contClic == 4) {
            l4.setVisible(true);
            tfTel4.setVisible(true);
        }
        if (contClic == 5) {
            l5.setVisible(true);
            tfTel5.setVisible(true);
        }
        if (contClic > 5) {
            contClic = 5;
        }
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnElimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnElimActionPerformed
        // TODO add your handling code here:
       
     
        if (contClic == 1) {
            l1.setVisible(false);
            tfTel1.setText("");
            tfTel1.setVisible(false);
        }
        if (contClic == 2) {
            l2.setVisible(false);
            tfTel2.setText("");
            tfTel2.setVisible(false);
        }
        if (contClic == 3) {
            l3.setVisible(false);
            tfTel3.setText("");
            tfTel3.setVisible(false);
        }
        if (contClic == 4) {
            l4.setVisible(false);
            tfTel4.setText("");
            tfTel4.setVisible(false);
        }
        if (contClic == 5) {
            l5.setVisible(false);
            tfTel5.setText("");
            tfTel5.setVisible(false);
        }
        if (contClic < 1) {
            contClic = 1;
        }
         contClic--;
    }//GEN-LAST:event_btnElimActionPerformed

    private void tfPass2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfPass2FocusLost
        // TODO add your handling code here:
        pass=tfPass1.getPassword();
        pass2=tfPass2.getPassword();
        
        if(pass.length<=3){
            JOptionPane.showMessageDialog(null, "No se permite una contraseña muy corta", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            tfPass1.setText("");
            tfPass2.setText("");
        }
        else{
            if(!Arrays.equals(pass, pass2)){
            JOptionPane.showMessageDialog(null, "Error las contraseñas no coinciden", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            tfPass1.setText("");
            tfPass2.setText("");
            }
        }
        
    }//GEN-LAST:event_tfPass2FocusLost

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if(AoM==0){//AoM=0: Funcion Agregar
            String sql;
            String nom=tfNom.getText();
            String ape1=tfApe1.getText();
            String ape2=tfApe2.getText();
            String dir=tfDir.getText();
            String tel=tfTel.getText();

            String usu=tfUsu.getText();
            pass=tfPass1.getPassword();
            String puesto=cbPuesto.getSelectedItem().toString().trim();

            Boolean tel1=tfTel1.isVisible()&&tfTel1.getText().equals("    -    ");
            Boolean tel2=tfTel2.isVisible()&&tfTel2.getText().equals("    -    ");
            Boolean tel3=tfTel3.isVisible()&&tfTel3.getText().equals("    -    ");
            Boolean tel4=tfTel4.isVisible()&&tfTel4.getText().equals("    -    ");
            Boolean tel5=tfTel5.isVisible()&&tfTel5.getText().equals("    -    ");

            if(nom.equals("")||tel.equals("")||dir.equals("")||ape1.equals("")||usu.equals("")||puesto.equals("")||"".equals(tfPass1.getText())||"".equals(tfPass2.getText())||tel1||tel2||tel3||tel4||tel5){
                JOptionPane.showMessageDialog(null, "Sólo el campo segundo apellido no es obligatorio, Complete los demás campos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            }else{

                 f= new Funciones();
                sql="INSERT INTO usuarios(nombre,primerApellido,segundoApellido,direccion,puesto,activo,usuario,pass) VALUES('"+nom+"','"+ape1+"','"+ape2+"','"+dir+"','"+puesto+"','1','"+usu+"','"+pass+"')";
                f.insertar(sql);
                /////Obtengo el codigo del usuario ingresado para guardar su telefono
                String codigo="SELECT * FROM usuarios";
                ResultSet rs = f.buscar(codigo);
                int cod = 0;
                try {
                    rs.last();
                    cod=rs.getInt(1);
                } catch (SQLException ex) {
                    Logger.getLogger(tablaUsuario.class.getName()).log(Level.SEVERE, null, ex);
                }
                f.cerrarConexion();
                String sql2="INSERT INTO tel_usuario VALUES('"+cod+"','"+tel+"')";
                f.insertar(sql2);
                
                insertarTelExtra(cod);
              
                mostrarTabla("SELECT * FROM usuarios WHERE activo=1");
                jdAccion.dispose();
            }
             
        }else{//AoM=1: Funcion Modificar
            String nombre, primer, segundo, dir;
            nombre = tfNom.getText();
            primer = tfApe1.getText();
            segundo = tfApe2.getText();//OPCIONAL
            dir = tfDir.getText();
            int codigo = Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            if (nombre.equals("") || primer.equals("") || dir.equals("")) {
                JOptionPane.showMessageDialog(null, "Sólo el campo segundo apellido no es obligatorio, Complete los demás campos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
            } else {
                String sql = "UPDATE usuarios SET nombre='" + nombre + "', primerApellido='" + primer + "', segundoApellido='" + segundo + "',direccion='" + dir + "' WHERE codUsuario='" + codigo + "'";
                f.insertar(sql);
                
                //Borro todos los numeros del usuario para volverlos agregar a la tabla tel_usuarios
                sql="DELETE FROM tel_usuario WHERE codUsuario='"+codigo+"'";
                f.insertar(sql);//elimina los datos de telefono del usuario correspondiente
                //Ingreso el telefono obligatorio
                String sql2="INSERT INTO tel_usuario VALUES('"+codigo+"','"+tfTel.getText()+"')";
                f.insertar(sql2);
                //reingreso los telefonos extras
                insertarTelExtra(codigo);
            }
            
            mostrarTabla("SELECT * FROM usuarios WHERE activo=1");
            jdAccion.dispose();
        }
              
        
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void insertarTelExtra(int cod){
        String sql2 = "";
       
            if(tfTel1.isVisible()){
                    if(tfTel1.getText().equals("    -    ")){//Campo telefono vacio
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_usuario VALUES('"+cod+"','"+tfTel1.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel2.isVisible()){
                    if(tfTel2.getText().equals("    -    ")){//Campo telefono vacio
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_usuario VALUES('"+cod+"','"+tfTel2.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel3.isVisible()){
                    if(tfTel3.getText().equals("    -    ")){//Campo telefono vacio
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_usuario VALUES('"+cod+"','"+tfTel3.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel4.isVisible()){
                    if(tfTel4.getText().equals("    -    ")){
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_usuario VALUES('"+cod+"','"+tfTel4.getText()+"')";
                        f.insertar(sql2);
                    }
                }
                if(tfTel5.isVisible()){
                    if(tfTel5.getText().equals("    -    ")){
                        JOptionPane.showMessageDialog(null, "No debe dejar campos vacíos", "ADVERTENCIA", JOptionPane.WARNING_MESSAGE);
                    }else{
                        sql2="INSERT INTO tel_usuario VALUES('"+cod+"','"+tfTel5.getText()+"')";
                        f.insertar(sql2);
                    }
                }
               
    }
    
    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        // TODO add your handling code here:
        this.tfApe1.setText("");
        this.tfApe2.setText("");
        this.tfDir.setText("");
        this.tfNom.setText("");
        this.tfPass1.setText("");
        this.tfPass2.setText("");
        this.tfTel.setText("");
        this.tfUsu.setText("");
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        jdAccion.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
        // TODO add your handling code here:
        AoM=1;
        lblTitulo2.setText("Modificar Datos de Usuario");
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="SELECT * FROM usuarios WHERE codUsuario='"+codigo+"'";
            
            conn=Conexion.obtenerConexion();
            try {
                stmt=conn.createStatement();
                rs=stmt.executeQuery(sql);
                while(rs.next()){
                    tfNom.setText(rs.getString(2));
                    tfApe1.setText(rs.getString(3));
                    tfApe2.setText(rs.getString(4));
                    tfDir.setText(rs.getString(5));
                    
                    tfUsu.setText(rs.getString(8));
                    tfPass1.setText(rs.getString(9));
                    tfPass2.setText(rs.getString(9));
                    cbPuesto.setSelectedItem(rs.getString(6));
                }
                ////////////////MOSTRAR TELEFONOS SEGUN EL NUMERO DE TELEFONOS GUADADOS
                String sql2="SELECT * FROM tel_usuario WHERE codUsuario='"+codigo+"'";
                rs=stmt.executeQuery(sql2);
                int x;//sirve para saber cuantos telefonos hay por cada usuario en la BD
                while(rs.next()){
                      x=rs.getRow();
                      if(x==1){
                          tfTel.setText(rs.getString(2));
                          l1.setVisible(false);
                          tfTel1.setVisible(false);
                          l2.setVisible(false);
                          tfTel2.setVisible(false);
                          l3.setVisible(false);
                          tfTel3.setVisible(false);
                          l4.setVisible(false);
                          tfTel4.setVisible(false);
                          l5.setVisible(false);
                          tfTel5.setVisible(false);
                          contClic=1;
                      }
                      if(x==2){
                          tfTel1.setText(rs.getString(2));
                          l1.setVisible(true);
                          tfTel1.setVisible(true);
                          contClic=2;
                      }
                      if(x==3){
                          tfTel2.setText(rs.getString(2));
                          l2.setVisible(true);
                          tfTel2.setVisible(true);
                          contClic=3;
                      }
                      if(x==4){
                          tfTel3.setText(rs.getString(2));
                          l3.setVisible(true);
                          tfTel3.setVisible(true);
                          contClic=4;
                      }
                      if(x==5){
                          tfTel4.setText(rs.getString(2));
                          l4.setVisible(true);
                          tfTel4.setVisible(true);
                          contClic=5;
                      }
                      if(x==6){
                          tfTel5.setText(rs.getString(2));
                          l5.setVisible(true);
                          tfTel5.setVisible(true);
                          contClic=6;
                      }
                }
                
                conn.close();
            } catch (SQLException ex) {
                JOptionPane.showMessageDialog(null, "Error al buscar: "+ex);
            }
        
        
        jdAccion.pack();
        jdAccion.setLocationRelativeTo(null);
        jdAccion.setVisible(true);
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un usuario");
        }
        
    }//GEN-LAST:event_btnModificarActionPerformed

    private void darBaja(){
        
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="UPDATE usuarios SET activo='0' WHERE codUsuario='"+codigo+"'";
            f.insertar(sql);
            sql="SELECT * FROM usuarios WHERE activo=1"; 
            mostrarTabla(sql);
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un usuario");
        }
        
    }
    private void darAlta(){
       
        try{
            int codigo=Integer.parseInt(dt.getValueAt(tablaClientes.getSelectedRow(), 0).toString());//Obtengo la codigo de la fila seleecionada
            String sql="UPDATE usuarios SET activo='1' WHERE codUsuario='"+codigo+"'";
            f.insertar(sql);
            sql="SELECT * FROM usuarios WHERE activo=0"; 
            mostrarTabla(sql);
        }catch(ArrayIndexOutOfBoundsException e){
            JOptionPane.showMessageDialog(null, "Debe elegir un usuario");
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
       
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(tablaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
             

                new tablaUsuario().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.edisoncor.gui.button.ButtonIcon btnAdd;
    private org.edisoncor.gui.button.ButtonIpod btnAtras;
    private org.edisoncor.gui.button.ButtonIpod btnCancelar;
    private org.edisoncor.gui.button.ButtonIpod btnDarAlta;
    private org.edisoncor.gui.button.ButtonIpod btnDarBaja;
    private org.edisoncor.gui.button.ButtonIcon btnElim;
    private org.edisoncor.gui.button.ButtonIpod btnGuardar;
    private org.edisoncor.gui.button.ButtonIpod btnLimpiar;
    private org.edisoncor.gui.button.ButtonIpod btnModificar;
    private org.edisoncor.gui.button.ButtonIpod btnNuevo;
    private org.edisoncor.gui.button.ButtonIpod btnVerBajas;
    private javax.swing.JComboBox cbPuesto;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JDialog jdAccion;
    private org.edisoncor.gui.label.LabelMetric l1;
    private org.edisoncor.gui.label.LabelMetric l2;
    private org.edisoncor.gui.label.LabelMetric l3;
    private org.edisoncor.gui.label.LabelMetric l4;
    private org.edisoncor.gui.label.LabelMetric l5;
    private org.edisoncor.gui.label.LabelMetric labelMetric1;
    private org.edisoncor.gui.label.LabelMetric labelMetric10;
    private org.edisoncor.gui.label.LabelMetric labelMetric11;
    private org.edisoncor.gui.label.LabelMetric labelMetric12;
    private org.edisoncor.gui.label.LabelMetric labelMetric3;
    private org.edisoncor.gui.label.LabelMetric labelMetric4;
    private org.edisoncor.gui.label.LabelMetric labelMetric5;
    private org.edisoncor.gui.label.LabelMetric labelMetric6;
    private org.edisoncor.gui.label.LabelMetric labelMetric7;
    private org.edisoncor.gui.label.LabelMetric labelMetric8;
    private org.edisoncor.gui.label.LabelMetric labelMetric9;
    private org.edisoncor.gui.label.LabelMetric lblTitulo2;
    private org.edisoncor.gui.panel.PanelCurves panelCurves1;
    private org.edisoncor.gui.panel.PanelCurves panelCurves2;
    private org.edisoncor.gui.panel.PanelImage panelImage2;
    private org.edisoncor.gui.panel.PanelImage panelImage3;
    private org.edisoncor.gui.panel.PanelRect panelRect1;
    private org.edisoncor.gui.panel.PanelRect panelRect2;
    private org.edisoncor.gui.panel.PanelRect panelRect3;
    private org.edisoncor.gui.panel.PanelRect panelRect4;
    private org.edisoncor.gui.panel.PanelRect panelRect5;
    private org.edisoncor.gui.panel.PanelRound panelRound1;
    private org.jdesktop.swingx.JXTable tablaClientes;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfApe1;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfApe2;
    private java.awt.TextField tfBuscar;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfDir;
    private org.edisoncor.gui.textField.TextFieldRectBackground tfNom;
    private org.edisoncor.gui.passwordField.PasswordFieldRectIcon tfPass1;
    private org.edisoncor.gui.passwordField.PasswordFieldRectIcon tfPass2;
    private javax.swing.JFormattedTextField tfTel;
    private javax.swing.JFormattedTextField tfTel1;
    private javax.swing.JFormattedTextField tfTel2;
    private javax.swing.JFormattedTextField tfTel3;
    private javax.swing.JFormattedTextField tfTel4;
    private javax.swing.JFormattedTextField tfTel5;
    private org.edisoncor.gui.textField.TextFieldRectIcon tfUsu;
    // End of variables declaration//GEN-END:variables
}
